trackfilter bools and case insensitive opts.
authortsteven4 <tsteven4@gmail.com>
Mon, 7 Jan 2019 16:57:41 +0000 (09:57 -0700)
committertsteven4 <tsteven4@gmail.com>
Mon, 7 Jan 2019 16:57:41 +0000 (09:57 -0700)
trackfilter.cc
trackfilter.h

index 35b660da29ec0aecd121b3ffe729606b50273233..e73a8299fe226a0be7cbffb0aeb4fc029d7bcb79 100644 (file)
@@ -75,7 +75,7 @@ qint64 TrackFilter::trackfilter_parse_time_opt(const char* arg)
 {
   qint64 result;
 
-  QRegularExpression re("^([+-]?\\d+)([dhms])$");
+  QRegularExpression re("^([+-]?\\d+)([dhms])$", QRegularExpression::CaseInsensitiveOption);
   assert(re.isValid());
   QRegularExpressionMatch match = re.match(arg);
   if (match.hasMatch()) {
@@ -213,7 +213,7 @@ void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track)   /* ca
     if (!wpt->creation_time.isValid()) {
       timeless_pts++;
     }
-    if (!(opt_merge && opt_discard) && (need_time != 0) && (!wpt->creation_time.isValid())) {
+    if (!(opt_merge && opt_discard) && need_time && (!wpt->creation_time.isValid())) {
       fatal(MYNAME "-init: Found track point at %f,%f without time!\n",
             wpt->latitude, wpt->longitude);
     }
@@ -225,7 +225,7 @@ void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track)   /* ca
       track_list[track_ct].last_time = wpt->GetCreationTime();
     }
 
-    if ((need_time != 0) && (prev != nullptr) && (prev->GetCreationTime() > wpt->GetCreationTime())) {
+    if (need_time && (prev != nullptr) && (prev->GetCreationTime() > wpt->GetCreationTime())) {
       if (opt_merge == nullptr) {
         QString t1 = prev->CreationTimeXML();
         QString t2 = wpt->CreationTimeXML();
@@ -446,7 +446,7 @@ void TrackFilter::trackfilter_split()
 
   opt_interval = (opt_split && (strlen(opt_split) > 0) && (0 != strcmp(opt_split, TRACKFILTER_SPLIT_OPTION)));
   if (opt_interval != 0) {
-    QRegularExpression re("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+))([dhms])$");
+    QRegularExpression re("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+))([dhms])$", QRegularExpression::CaseInsensitiveOption);
     assert(re.isValid());
     QRegularExpressionMatch match = re.match(opt_split);
     if (match.hasMatch()) {
@@ -482,7 +482,7 @@ void TrackFilter::trackfilter_split()
 
   opt_distance = (opt_sdistance && (strlen(opt_sdistance) > 0) && (0 != strcmp(opt_sdistance, TRACKFILTER_SDIST_OPTION)));
   if (opt_distance != 0) {
-    QRegularExpression re("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+))([km])$");
+    QRegularExpression re("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+))([km])$", QRegularExpression::CaseInsensitiveOption);
     assert(re.isValid());
     QRegularExpressionMatch match = re.match(opt_sdistance);
     if (match.hasMatch()) {
@@ -918,7 +918,7 @@ void TrackFilter::trackfilter_faketime()
   }
 }
 
-int TrackFilter::trackfilter_points_are_same(const Waypoint* wpta, const Waypoint* wptb)
+bool TrackFilter::trackfilter_points_are_same(const Waypoint* wpta, const Waypoint* wptb)
 {
   // We use a simpler (non great circle) test for lat/lon here as this
   // is used for keeping the 'bookends' of non-moving points.
@@ -1010,7 +1010,7 @@ void TrackFilter::init()
               );
   /* in case of a formated title we also need valid timestamps */
   if ((opt_title != nullptr) && (strchr(opt_title, '%') != nullptr)) {
-    need_time = 1;
+    need_time = true;
   }
 
   track_ct = 0;
@@ -1153,17 +1153,17 @@ void TrackFilter::process()
     }
   }
 
-  int something_done = 0;
+  bool something_done = false;
 
   if ((opt_pack != nullptr) || (opts == -1)) { /* call our default option */
     trackfilter_pack();
-    something_done = 1;
+    something_done = true;
   } else if (opt_merge != nullptr) {
     trackfilter_merge();
-    something_done = 1;
+    something_done = true;
   }
 
-  if ((something_done == 1) && (--opts <= 0)) {
+  if (something_done && (--opts <= 0)) {
     if (opt_title != nullptr) {
       trackfilter_title();
     }
index ce19357a0fde28f62d6ed1292b8cd005ff58d865..8eae7fb879bf454d8afb868399db96c51621814a 100644 (file)
@@ -181,7 +181,7 @@ private:
   int timeless_pts = 0;
   int opt_interval = 0;
   int opt_distance = 0;
-  char need_time;              /* initialized within trackfilter_init */
+  bool need_time;              /* initialized within trackfilter_init */
 
   int trackfilter_opt_count();
   qint64 trackfilter_parse_time_opt(const char* arg);
@@ -221,7 +221,7 @@ private:
 
   faketime_t trackfilter_faketime_check(const char* timestr);
   void trackfilter_faketime();             /* returns number of track points left after filtering */
-  int trackfilter_points_are_same(const Waypoint* wpta, const Waypoint* wptb);
+  bool trackfilter_points_are_same(const Waypoint* wpta, const Waypoint* wptb);
 
   void trackfilter_segment_head(const route_head* rte);